//
//  UILabel+Extension.m
//  Weibo-OC
//
//  Created by 焦林生 on 15/11/26.
//  Copyright © 2015年 cn.baidu. All rights reserved.
//

#import "UILabel+Extension.h"

@implementation UILabel (Extension)

/**
 *  UILabel扩展
 *
 *  @param title    标题
 *  @param fontSize 字体大小
 *  @param color    字体颜色
 *
 *  @return UILabel
 */
+ (UILabel *)initWithTitle:(NSString *)title fontSize:(CGFloat )fontSize color:(UIColor *)color screenInset:(CGFloat )screenInset {

    UILabel *label = [[UILabel alloc]init];
    
    label.text = title;
    label.font = [UIFont systemFontOfSize:fontSize];
    label.textColor = color;
    label.numberOfLines = 0;
    
    //screenInset 相对与屏幕左右的缩紧，默认为0，局中显示，如果设置，则左对齐
    if (screenInset == 0) {
        label.textAlignment = NSTextAlignmentCenter;
    } else {
    
        //设置换行宽度
        label.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - 2 * screenInset;
        label.textAlignment = NSTextAlignmentLeft;
    }
    
    [label sizeToFit];
    
    return label;
}
@end
